package handler

import (
	"Gin/Api/request"
	"Gin/global/model"
	"UserSrv/user"
	"ViewSrv/view"
	context2 "context"
	"github.com/gin-gonic/gin"
	"net/http"
)

func UserData(context *gin.Context) {
	var UserDateRequest request.UserDataRequest
	if err := context.ShouldBind(&UserDateRequest); err != nil {
		context.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
		return
	}
	log, err := model.ViewClient.ViewLog(context2.Background(), &view.ViewLogRequest{
		UserId: UserDateRequest.UserId,
	})
	if err != nil {
		context.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
		return
	}
	getUser, err := model.UserClient.GetUser(context2.Background(), &user.GetUserRequest{UserId: UserDateRequest.UserId})
	if err != nil {
		context.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
		return
	}
	context.JSON(http.StatusOK, gin.H{
		"log":  log,
		"user": getUser,
	})
}
